<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index stored in mapped file using Boost.Interprocess</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Chapter 1. Geometry">
<link rel="up" href="../rtree_examples.html" title="Examples">
<link rel="prev" href="index_stored_in_shared_memory_using_boost_interprocess.html" title="Index stored in shared memory using Boost.Interprocess">
<link rel="next" href="../../reference.html" title="Reference">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="index_stored_in_shared_memory_using_boost_interprocess.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rtree_examples.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../reference.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="geometry.spatial_indexes.rtree_examples.index_stored_in_mapped_file_using_boost_interprocess"></a><a class="link" href="index_stored_in_mapped_file_using_boost_interprocess.html" title="Index stored in mapped file using Boost.Interprocess">Index
        stored in mapped file using Boost.Interprocess</a>
</h4></div></div></div>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>

<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">interprocess</span><span class="special">/</span><span class="identifier">managed_mapped_file</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">point</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">index</span><span class="special">/</span><span class="identifier">rtree</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">namespace</span> <span class="identifier">bi</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">interprocess</span><span class="special">;</span>
<span class="keyword">namespace</span> <span class="identifier">bg</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">;</span>
<span class="keyword">namespace</span> <span class="identifier">bgm</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">;</span>
<span class="keyword">namespace</span> <span class="identifier">bgi</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">index</span><span class="special">;</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">typedef</span> <span class="identifier">bgm</span><span class="special">::</span><span class="identifier">point</span><span class="special">&lt;</span><span class="keyword">float</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">&gt;</span> <span class="identifier">point_t</span><span class="special">;</span>

    <span class="keyword">typedef</span> <span class="identifier">point_t</span> <span class="identifier">value_t</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">linear</span><span class="special">&lt;</span><span class="number">32</span><span class="special">,</span> <span class="number">8</span><span class="special">&gt;</span> <span class="identifier">params_t</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">indexable</span><span class="special">&lt;</span><span class="identifier">value_t</span><span class="special">&gt;</span> <span class="identifier">indexable_t</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">equal_to</span><span class="special">&lt;</span><span class="identifier">value_t</span><span class="special">&gt;</span> <span class="identifier">equal_to_t</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">bi</span><span class="special">::</span><span class="identifier">allocator</span><span class="special">&lt;</span><span class="identifier">value_t</span><span class="special">,</span> <span class="identifier">bi</span><span class="special">::</span><span class="identifier">managed_mapped_file</span><span class="special">::</span><span class="identifier">segment_manager</span><span class="special">&gt;</span> <span class="identifier">allocator_t</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">rtree</span><span class="special">&lt;</span><span class="identifier">value_t</span><span class="special">,</span> <span class="identifier">params_t</span><span class="special">,</span> <span class="identifier">indexable_t</span><span class="special">,</span> <span class="identifier">equal_to_t</span><span class="special">,</span> <span class="identifier">allocator_t</span><span class="special">&gt;</span> <span class="identifier">rtree_t</span><span class="special">;</span>

    <span class="special">{</span>
        <span class="identifier">bi</span><span class="special">::</span><span class="identifier">managed_mapped_file</span> <span class="identifier">file</span><span class="special">(</span><span class="identifier">bi</span><span class="special">::</span><span class="identifier">open_or_create</span><span class="special">,</span> <span class="string">"data.bin"</span><span class="special">,</span> <span class="number">1024</span><span class="special">*</span><span class="number">1024</span><span class="special">);</span>
        <span class="identifier">allocator_t</span> <span class="identifier">alloc</span><span class="special">(</span><span class="identifier">file</span><span class="special">.</span><span class="identifier">get_segment_manager</span><span class="special">());</span>
        <span class="identifier">rtree_t</span> <span class="special">*</span> <span class="identifier">rtree_ptr</span> <span class="special">=</span> <span class="identifier">file</span><span class="special">.</span><span class="identifier">find_or_construct</span><span class="special">&lt;</span><span class="identifier">rtree_t</span><span class="special">&gt;(</span><span class="string">"rtree"</span><span class="special">)(</span><span class="identifier">params_t</span><span class="special">(),</span> <span class="identifier">indexable_t</span><span class="special">(),</span> <span class="identifier">equal_to_t</span><span class="special">(),</span> <span class="identifier">alloc</span><span class="special">);</span>

        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">rtree_ptr</span><span class="special">-&gt;</span><span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>

        <span class="identifier">rtree_ptr</span><span class="special">-&gt;</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">point_t</span><span class="special">(</span><span class="number">1.0</span><span class="special">,</span> <span class="number">1.0</span><span class="special">));</span>
        <span class="identifier">rtree_ptr</span><span class="special">-&gt;</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">point_t</span><span class="special">(</span><span class="number">2.0</span><span class="special">,</span> <span class="number">2.0</span><span class="special">));</span>

        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">rtree_ptr</span><span class="special">-&gt;</span><span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="special">{</span>
        <span class="identifier">bi</span><span class="special">::</span><span class="identifier">managed_mapped_file</span> <span class="identifier">file</span><span class="special">(</span><span class="identifier">bi</span><span class="special">::</span><span class="identifier">open_or_create</span><span class="special">,</span> <span class="string">"data.bin"</span><span class="special">,</span> <span class="number">1024</span><span class="special">*</span><span class="number">1024</span><span class="special">);</span>
        <span class="identifier">allocator_t</span> <span class="identifier">alloc</span><span class="special">(</span><span class="identifier">file</span><span class="special">.</span><span class="identifier">get_segment_manager</span><span class="special">());</span>
        <span class="identifier">rtree_t</span> <span class="special">*</span> <span class="identifier">rtree_ptr</span> <span class="special">=</span> <span class="identifier">file</span><span class="special">.</span><span class="identifier">find_or_construct</span><span class="special">&lt;</span><span class="identifier">rtree_t</span><span class="special">&gt;(</span><span class="string">"rtree"</span><span class="special">)(</span><span class="identifier">params_t</span><span class="special">(),</span> <span class="identifier">indexable_t</span><span class="special">(),</span> <span class="identifier">equal_to_t</span><span class="special">(),</span> <span class="identifier">alloc</span><span class="special">);</span>

        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">rtree_ptr</span><span class="special">-&gt;</span><span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>

        <span class="identifier">rtree_ptr</span><span class="special">-&gt;</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">point_t</span><span class="special">(</span><span class="number">3.0</span><span class="special">,</span> <span class="number">3.0</span><span class="special">));</span>
        <span class="identifier">rtree_ptr</span><span class="special">-&gt;</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">point_t</span><span class="special">(</span><span class="number">4.0</span><span class="special">,</span> <span class="number">4.0</span><span class="special">));</span>

        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">rtree_ptr</span><span class="special">-&gt;</span><span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
        </p>
<h5>
<a name="geometry.spatial_indexes.rtree_examples.index_stored_in_mapped_file_using_boost_interprocess.h0"></a>
          <span class="phrase"><a name="geometry.spatial_indexes.rtree_examples.index_stored_in_mapped_file_using_boost_interprocess.expected_results"></a></span><a class="link" href="index_stored_in_mapped_file_using_boost_interprocess.html#geometry.spatial_indexes.rtree_examples.index_stored_in_mapped_file_using_boost_interprocess.expected_results">Expected
          results</a>
        </h5>
<pre class="programlisting"><span class="number">0</span>
<span class="number">2</span>
<span class="number">2</span>
<span class="number">4</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2009-2021 Barend Gehrels,
      Bruno Lalande, Mateusz Loskot, Adam Wulkiewicz, Oracle and/or its affiliates<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="index_stored_in_shared_memory_using_boost_interprocess.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rtree_examples.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../reference.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
